package com.tensquare.qa.controller;

import annotation.Log;
import com.tensquare.qa.pojo.Problem;
import com.tensquare.qa.service.ProblemService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @Author: xuxiaoyu
 * @Create: 2019-11-20 23:19
 */
@RestController
@CrossOrigin
@RequestMapping("/qa")
public class ProblemController {
    @Autowired
    private ProblemService problemService;

    @Log("根据标签ID查询最新问题列表")
    @RequestMapping(value="/newlist/{labelId}/{page}/{size}",method= RequestMethod.GET)
    public Result findNewListByLabelId(@PathVariable String labelId, @PathVariable int page,@PathVariable int size){
        Page<Problem> list = problemService.findNewListByLabelId(labelId, page, size);
        PageResult pageResult = new PageResult(list.getTotalElements(), list.getContent());
        return new Result(true, StatusCode.OK,"查询成功",pageResult);
    }
    @Log("根据标签ID查询热门问题列表")
    @RequestMapping(value = "/hotlist/{labelId}/{page}/{size}",method = RequestMethod.GET)
    public Result findHotListByLabelId(@PathVariable String labelId,@PathVariable int page,@PathVariable int size){
        Page<Problem> list = problemService.findHotListByLabelId(labelId, page, size);
        PageResult<Problem> problemPageResult = new PageResult<>(list.getTotalElements(), list.getContent());
        return new Result(true,StatusCode.OK,"查询成功",problemPageResult);
    }
    @Log("根据标签ID查询等待问题列表")
    @RequestMapping(value = "/waitlist/{labelId}/{page}/{size}",method = RequestMethod.GET)
    public Result findWaitListByLabelId(@PathVariable String labelId,@PathVariable int page,@PathVariable int size){
        Page<Problem> list = problemService.findWaitListByLabelId(labelId, page, size);
        PageResult<Problem> problemPageResult = new PageResult<>(list.getTotalElements(), list.getContent());
        return new Result(true,StatusCode.OK,"查询成功",problemPageResult);
    }
}
